define(function (require, exports, module){
    'use strict';
    var $ = require('jquery'),
        _ = require('underscore'),
        Backbone = require('backbone'),
        notify = require('js/utils/notify'),
        models = require('js/apps/console/models'),
        utils = require('js/utils/tools'),
        app = Backbone.history;

    require('multiselect');

    var WelcomeView = Backbone.View.extend({
        tagName: "div",
        events: {
        },

        initialize: function (options) {
            this.options = options;
            this.collection = new models.UserCollection();
            this.collection.bind('change reset remove', this.renderWithData, this);
        },
        render: function () {
            this.$el.html("");
            $(window).scrollTop(0);
            return this;
        },
        renderWithData: function () {
            this.$el.html(this.template({
                items: this.collection.toJSON(),
            }));
            var that = this;
            utils.renderTable('main-list', {
                $orderby: that.options.$orderby || 'id',
                sortCallback: function (field) {
                    that.options.$orderby = field;
                    that.options.$page = 1;
                    var newUrl = utils.composeQueryString('#console/welcome/', that.options);
                    app.navigate(newUrl, {
                        trigger: true
                    });
                }
            });
            utils.getPaginator(that.options, this.collection.total, '#console/welcome/');

            return this;
        },

        load:function(){
            this.collection.fetch({
                reset: true,
                data: this.options,
                error: function (c, r, o) {
                    notify.notifyResp(r);
                },
            });
        },

    });

    exports.List = Backbone.View.extend({
        el: "#content_wrapper",
        template: "console/Welcome.html",
        initialize: function (options) {
            this.options = options;
        },
        render: function () {
            this.options.$size = 300;
            var view = new WelcomeView(this.options);
            view.template = this.template;
            this.$el.empty();
            this.$el.append(view.render().el);
            view.load();

            return this;
        }
    });

});